//////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //---------------------------- Ebrahim Foulaadvand, 17 July 2013 ----------------- // // // // The routine "Traffic" solves the 1D traffic equation using the FTCS, Lax and Lax-Wendroff methods. // // Periodic boundary condition is used. The system length L is set to one. Initial wave shape is a step // // // function. // // // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include using namespace std; main() { double tau=0.001,h,L=1,x,vmax=1,rhomax=1; int N=200,i,n,T=3000; ofstream file0 ("initial profile n=0.plt"); //output file for the profile at timestep n=0. ofstream file1 ("profile FTCS n=10.plt"); //output file for the profile at timestep n=100. ofstream file2 ("profile FTCS n=20.plt"); //output file for the profile at timestep n=500. ofstream file3 ("profile FTCS n=30.plt"); //output file for the profile at timestep n=500. ofstream file4 ("profile Lax n=100.plt"); //output file for the profile at timestep n=500. ofstream file5 ("profile Lax n=200.plt"); //output file for the profile at timestep n=500. ofstream file6 ("profile Lax n=300.plt"); //output file for the profile at timestep n=500. ofstream file7 ("profile LW n=1000.plt"); //output file for the profile at timestep n=500. ofstream file8 ("profile LW n=2000.plt"); //output file for the profile at timestep n=500. ofstream file9 ("profile LW n=3000.plt"); //output file for the profile at timestep n=500. ofstream file10("profile analytic n=100.plt"); ofstream file11("profile analytic n=200.plt"); ofstream file12("profile analytic n=300.plt"); vector rhoanal(N+1,0),rho(N+1,0),rhonew(N+1,0),rhoL(N+1,0),rhoLnew(N+1,0),rhoLW(N+1,0),rhoLWnew(N+1,0), rhohalfminus(N+1,0),rhohalfplus(N+1,0),chalfminus(N+1,0),chalfplus(N+1,0),J(N+1,0), JL(N+1,0),JLW(N+1,0); // Arrays "rho" and "rhonew" store the current and updated values of the density rho(x,t) at grid points. // "L" stands for Lax and "LW" stands for Lax-Wendroff. h=L/N; cout<<"h= "<-vmax*tau*n && x=vmax*tau*n) rhoanal[i]=0.0; file10<<(-0.5*L+i*h)<<" "<-vmax*tau*n && x=vmax*tau*n) rhoanal[i]=0.0; file11<<(-0.5*L+i*h)<<" "<-vmax*tau*n && x=vmax*tau*n) rhoanal[i]=0.0; file12<<(-0.5*L+i*h)<<" "<